import React from 'react';
import ReactDOM from 'react-dom';
import { message, Spin } from 'antd';
import './index.css';
import App from './App';
import ZhuYuan from './views/ZhuYuan/ZhuYuan';
import MenZhen from './views/MenZhen/MenZhen';
import axios from 'axios'

import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom';

axios.defaults.baseURL="http://172.17.3.219:15555/"


//声明一个空的对象；
let loadingInstance;
let spinState="true"
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  console.log(config);
  var dom = document.createElement('div')
  dom.setAttribute('id', 'loading')
  document.body.appendChild(dom)
  // 在发送请求之前做些什么,全屏加载
  // 显示加载动画
  loadingInstance = ReactDOM.render(<Spin spinning={spinState} size="large" tip="努力加载中。。。。。" />, dom)
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});


// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  console.log(response)
  console.log(loadingInstance)
  // 对响应数据做点什么
  // 关闭动画
  // setTimeout(,1000)
  document.body.removeChild(document.getElementById('loading'))
  return response;
}, function (error) {
  // 对响应错误做点什么
  console.log("111")
  setTimeout(document.body.removeChild(document.getElementById('loading')),3000)
   message.error('请求数据失败，请重试！！！！',10);
  return Promise.reject(error);
});

ReactDOM.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
